<template>
  <div class="container">
    <template v-for="(item, index) in accountRecharges">
      <el-badge
        :key="index"
        :value="`第 ${index + 1} 张`"
        class="item mt1"
        type="primary"
      >
        <div class="invoice">
          <div class="invoice-round left">
            <i
              :key="item"
              class="round"
              v-for="item in 15"
            ></i>
          </div>
          <div class="invoice-body">
            <div class="invoice-header">
              <div class="invoice-title">
                <h1>湖南{{ item.InvoiceType }}</h1>
              </div>
            </div>
            <div class="invoice-date">
              <span class="yellow"></span>
              开票日期:
              <span class="print ml1">
                {{
                new Date().format("yyyy年MM月dd日")
                }}
              </span>
            </div>
            <table
              :key="index"
              align="center"
              bgcolor="#cd8846"
              border="0"
              cellpadding="4"
              cellspacing="1.6"
              class="tabtop13"
              width="100%"
            >
              <tr>
                <td
                  colspan="1"
                  rowspan="1"
                  width="1%"
                >
                  <div class="wv">购买方</div>
                </td>
                <td
                  colspan="16"
                  width="100%"
                >
                  <div class="row">
                    <div style="width: 7rem">
                      <div class="font-justify">名称</div>
                      <div class="font-justify">纳税人识别号</div>
                      <div class="font-justify">地址、电话</div>
                      <div class="font-justify">开户行及账户</div>
                    </div>
                    <div style="width: 3%">
                      <div>:</div>
                      <div>:</div>
                      <div>:</div>
                      <div>:</div>
                    </div>
                    <div
                      class="font-left"
                      style="width: 80%"
                    >
                      <div class="print block">{{ item.BuyerName }}</div>
                      <div class="print block">{{ item.BuyerTAXID }}</div>
                      <div class="print block">
                        {{ item.BuyerAddressTelePhone || " " }}
                        <span></span>
                      </div>
                      <div class="print block">{{ item.BuyerBankAccount }}</div>
                    </div>
                  </div>
                </td>

                <td
                  colspan="1"
                  rowspan="1"
                  width="1%"
                >
                  <div class="text-v">密码区</div>
                </td>
                <td
                  colspan="10"
                  rowspan="1"
                  width="10%"
                ></td>
              </tr>

              <tr>
                <td
                  colspan="7"
                  width="20%"
                >
                  <div>货物或应税劳务、服务名称</div>
                  <div class="block">
                    <span class="print">{{ item.Invoicesubject }}</span>
                  </div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block">合 计</div>
                </td>
                <td
                  colspan="3"
                  width="9%"
                >
                  <div>规格型号</div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                </td>
                <td
                  colspan="3"
                  width="9%"
                >
                  <div>单位</div>
                  <div>
                    <span class="print">次</span>
                  </div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                </td>
                <td
                  colspan="3"
                  width="9%"
                >
                  <div>数量</div>
                  <div>
                    <span class="print">1</span>
                  </div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                </td>
                <td
                  colspan="3"
                  width="9%"
                >
                  <div>单价</div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                </td>
                <td
                  colspan="3"
                  width="9%"
                >
                  <div>金额</div>
                  <div>
                    <span class="print">{{ item.Amount }}</span>
                  </div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class>
                    <span class="print">￥{{ item.Amount }}</span>
                  </div>
                </td>
                <td
                  colspan="3"
                  width="9%"
                >
                  <div>税率</div>
                  <div>
                    <span class="print">6%</span>
                  </div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                </td>
                <td
                  colspan="3"
                  width="9%"
                >
                  <div>税额</div>

                  <div>
                    <span class="print">{{ item.TaxAmount }}</span>
                  </div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block"></div>
                  <div class="block">
                    <span class="print">￥{{ item.TaxAmount }}</span>
                  </div>
                </td>
                <!-- <td colspan="5" width="18%">
                  <div>含税金额</div>
                  <div>(最大值:1059998)</div>
                  <div>
                    <span class="print">{{ item.InvoiceAmount }}</span>
                  </div>
                  <div class="block"></div>
                  <div class="block"></div>
                </td>-->
              </tr>
              <!-- <tr>
                <td colspan="6"></td>
                <td colspan="2"></td>
                <td colspan="2">次</td>
                <td colspan="2">1</td>
                <td colspan="2">{{ item.invoiceAmount / 1.06 }}</td>
                <td colspan="2">
                  {{ (item.invoiceAmount / 1.06).toFixed(2) }}
                </td>
                <td colspan="2">6%</td>
                <td colspan="2">
                  {{ ((item.invoiceAmount / 1.06) * 0.06).toFixed(2) }}
                </td>
                <td colspan="2">123</td>
              </tr>-->

              <tr>
                <td colspan="7">价税合计（大写）</td>
                <td colspan="21">
                  <div class="row">
                    <div
                      class="col-1"
                      style="text-align: left; padding-left: 1em"
                    >
                      <span class="print">
                        <i class="el-icon-circle-close"></i>
                        {{ changeNumMoneyToChinese(item.InvoiceTaxAmount) }}
                      </span>
                    </div>
                    <div class="col-1">
                      （小写）
                      <span class="print">￥ {{ Number(item.InvoiceTaxAmount).toFixed(2) }}</span>
                    </div>
                  </div>
                </td>
              </tr>
              <tr>
                <td colspan="1">
                  <div class="wv">销售方</div>
                </td>
                <td colspan="16">
                  <div class="row">
                    <div style="width: 7rem">
                      <div class="font-justify">名称</div>
                      <div class="font-justify">纳税人识别号</div>
                      <div class="font-justify">地址、电话</div>
                      <div class="font-justify">开户行及账户</div>
                    </div>
                    <div style="width: 3%">
                      <div>:</div>
                      <div>:</div>
                      <div>:</div>
                      <div>:</div>
                    </div>
                    <div
                      class="font-left"
                      style="width: 80%"
                    >
                      <div class="print">{{ item.ServiceProviderName }}</div>
                      <div class="print">{{ item.SellerTAXID }}</div>
                      <div class="print">{{ item.SellerAddressTelePhone }}</div>
                      <div class="print">{{ item.SellerBankAccount }}</div>
                    </div>
                  </div>
                </td>
                <td colspan="1">
                  <div class="wv">备注</div>
                </td>
                <td
                  class="remarks"
                  colspan="10"
                >
                  <div class="print text">{{ item.Remarks }}</div>
                </td>
              </tr>
            </table>

            <div class="row jcsa invoice-footer">
              <div>收款人：</div>
              <div>复核：</div>
              <div>开票人：</div>
              <div>销售方：（章）</div>
            </div>
          </div>
          <div class="invoice-round right">
            <i
              :key="item"
              class="round"
              v-for="item in 15"
            ></i>
          </div>
        </div>
      </el-badge>
    </template>

    <div class="operation row jcsa pb-2">
      <div class="cancel">
        <el-button
          @click="$router.replace('/invoiceApplyList')"
          type="info"
        >取消</el-button>
      </div>
      <div class="submit">
        <el-button
          @click="onSubmit"
          type="success"
        >确定提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { changeNumMoneyToChinese } from "../../plugins/changeNumMoneyToChinese";
export default {
  data() {
    return {
      zhanwei: "",
      remark: "",
      invoices: [],
      accountRecharges: [],
      // 金额
      invoiceAmount: 0,
      invoiceAmount2: 0,

      inputAmount: "",
      nowDate: new Date().toLocaleDateString(),
    };
  },
  async created() {
    let { accountRecharges } = this.$route.params;
    console.log(accountRecharges);
    if (accountRecharges && accountRecharges.length > 0) {
      this.accountRecharges = [...accountRecharges];
    } else {
      this.$router.push("/invoiceApplyList");
    }
  },
  methods: {
    // 差额
    difference() {
      let total = this.invoices.reduce(
        (total, cur) => total + cur.invoiceAmount,
        0
      );
      return this.invoiceAmount - total;
    },
    async onSubmit() {
      console.log(this.accountRecharges);
      for (let i = 0; i < this.accountRecharges.length; i++) {
        const element = this.accountRecharges[i];
        element.MerchantName = element.BuyerName;
        this.$http.post("/api/invoiceApply/Create", element);
      }
      this.$message.success("开票成功");
      this.$router.push("successfully");
    },
    changeNumMoneyToChinese,
  },
};
</script>
<style lang="less" scoped>
.container {
  width: 100%;
  padding: 0 5rem;
  display: flex;
  flex-direction: column;
  .invoice {
    border: 2px solid #8bbdff;
    width: 100%;
    display: flex;
    font-family: "楷体";
    color: #cd8846; // 409eff

    .invoice-round {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;

      &.left {
        border-right: 2px dashed #8bbdff;
      }
      &.right {
        border-left: 2px dashed #8bbdff;
      }
      .round {
        border: 2px solid #8bbdff;
        border-radius: 50%;
        width: 1.3rem;
        height: 1.3rem;
        display: block;
        margin-bottom: 1rem;
        &:first-child {
          margin-top: 1rem;
        }
      }
    }
    .invoice-body {
      flex: 23;
      padding: 2rem 2rem;
      .invoice-header {
        height: 6rem;
        display: flex;
        justify-content: center;
        align-items: center;
        .invoice-title {
          font-size: 1.3rem;
          > h1 {
            border-bottom: 4px double #cd8846;
            padding: 1rem;
          }
        }
      }
      .invoice-date {
        display: flex;
        justify-content: flex-end;
        align-items: flex-end;
      }
      .invoice-footer {
        margin-top: 1ex;
      }
    }
    // padding: 0 1rem;
    .el-badge {
      width: 100%;
    }
  }
  .operation {
    margin: 1rem;
    width: 100%;
  }
}

/* CSS Document */
.tabtop13 {
  margin-top: 13px;

  display: table;
  border-collapse: separate;

  text-indent: initial;
  // border-spacing: 2px;
  border-color: #c87c35 !important;
  border-top-color: #c87c35;
  border-right-color: #c87c35;
  border-bottom-color: #c87c35;
  border-left-color: #c87c35;

  td {
    background-color: #ffffff;
    height: 25px;
    line-height: 150%;
    text-align: center;
  }
}
.font-center {
  text-align: center;
}
.btbg {
  background: #e9faff !important;
}

.title {
  font-family: 微软雅黑;
  font-size: 26px;
  font-weight: bold;
  border-bottom: 1px dashed #c87c35;
  color: #255e95;
}
.titfont {
  font-family: 微软雅黑;
  font-size: 16px;
  font-weight: bold;
  color: #255e95;
  background-color: #e9faff;
}
.text-v {
  width: 1rem;
  margin: 0 auto;
}
.remarks {
  text-align: left !important;
  .text {
    height: 100%;
  }
}
.print {
  font-size: 1rem;
}
</style>
